package customize

import (
	"gitcode.com/G-YT/baoyou/server/global"
	"gitcode.com/G-YT/baoyou/server/model/common/response"
	"gitcode.com/G-YT/baoyou/server/model/customize"
	"gitcode.com/G-YT/baoyou/server/utils"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type HealthAnalyseApi struct {
}

// SaveHealthReport 保存健康报告
// @Tags HealthAnalyse
// @Summary 保存健康报告
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /disease/SaveHealthReport [post]
func (healthAnalyseApi *HealthAnalyseApi) SaveHealthReport(c *gin.Context) {
	var dd customize.HealthReport
	err := c.ShouldBindJSON(&dd)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	verify := utils.Rules{
		"disease_type_ids": {utils.NotEmpty()},
		"disease_ids":      {utils.NotEmpty()},
	}
	if err := utils.Verify(dd, verify); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	id := utils.GetUserID(c)
	dd.Uid = id
	if SaveReportsErr := HealthAnalyseService.SaveHealthReport(dd); SaveReportsErr != nil {
		global.GVA_LOG.Error("提交失败!", zap.Error(SaveReportsErr))
		response.FailWithMessage("提交失败", c)
	} else {
		response.Result(200, "", "提交成功", c)
	}
}
